package com.teng.smartdrawer.view.pullzoom;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;


public class InternalScrollView extends ScrollView {
    
    private PullToZoomScrollViewEx.OnScrollViewChangedListener onScrollViewChangedListener;
    
    
    private OnScrollToBottomListener onScrollToBottom;

    public void setOnScrollToBottomLintener(OnScrollToBottomListener listener) {
	onScrollToBottom = listener;
    }

    public interface OnScrollToBottomListener {
	public void onScrollBottomListener(boolean isBottom);

//	public void onSetLoadInfo(boolean b);

    }

    public InternalScrollView(Context context) {
        this(context, null);
    }

    public InternalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setOnScrollViewChangedListener(PullToZoomScrollViewEx.OnScrollViewChangedListener onScrollViewChangedListener) {
        this.onScrollViewChangedListener = onScrollViewChangedListener;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (onScrollViewChangedListener != null) {
            onScrollViewChangedListener.onInternalScrollChanged(l, t, oldl, oldt);
        }

        if(mScrollToTopListener != null  && t > oldt ){
            mScrollToTopListener.scrollToTop();
        }
        
//	if(Math.abs(oldt  -  t) > 3){
//		if (null != onScrollToBottom) {
//			onScrollToBottom.onSetLoadInfo(false);
//		}
//	}else{
//		if (null != onScrollToBottom) {
//			onScrollToBottom.onSetLoadInfo(true);
//		}
//	}
    }


    public ScrollToTopListener  mScrollToTopListener = null;

    public void setScrollToTopListener(ScrollToTopListener listener){
        this.mScrollToTopListener  = listener;
    }

    public interface ScrollToTopListener{
        void scrollToTop();
    }
    
	@Override
	    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX,
	    		boolean clampedY) {
	    	super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
			if (null != onScrollToBottom) {
				onScrollToBottom.onScrollBottomListener(clampedY);
	        } 
	    }
}
